﻿using BAL;
using DAL.DataTransferObject;
using Module.QLGiamGia;
using Module.QLHangHoa;
using Module.QLHoaDon;
using Module.QLKhachHang;
using Module.QLNhanVien;
using Module.QLNhaPhanPhoi;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace QLBH
{
    public partial class frmMain : Form
    {
        public static bool isQuit = true;
        public NhanVien objNhanVien;

        public frmMain()
        {
            InitializeComponent();
        }


        public frmMain(NhanVien nv)
        {
            InitializeComponent();
            objNhanVien = nv;
        }


        private void button2_Click(object sender, EventArgs e)
        {
            foreach (var item in this.Controls)
                if (item.GetType() == typeof(MdiClient))
                {
                    MdiClient client = item as MdiClient;
                    client.Controls.Clear();
                }
        }

        private void buttonsClicked(object sender, EventArgs e)
        {
        }

        Color[] arrColors = { Color.AntiqueWhite, Color.BlueViolet, Color.Chartreuse, Color.Crimson, Color.MediumVioletRed, Color.Cyan, Color.MidnightBlue, Color.DarkBlue, Color.DarkCyan, Color.DarkSlateGray, Color.DarkTurquoise, Color.DarkViolet, Color.DeepPink, Color.DeepSkyBlue, Color.Teal, Color.SpringGreen, Color.SteelBlue };

        private void frmMain_Load(object sender, EventArgs e)
        {
            btnAvatar.Text = objNhanVien.tenNV[0].ToString().ToUpper();
            lblAccount.Text = objNhanVien.tenNV.ToString();
            lblChucVu.Text = objNhanVien.chucVu;
            Random rnd = new Random();
            int colorIndex = rnd.Next(0, arrColors.Length - 1);
            btnAvatar.BackColor = arrColors[colorIndex];
        }

        private void panelFeatureMouseHover(object sender, EventArgs e)
        {
            var temp = sender as Control;
            if (temp.Name.Contains("pnl"))
            {
                Panel tempPanel = sender as Panel;
                foreach (Panel item in panel1.Controls)
                    if (item.Name == tempPanel.Name && item.BackColor != Color.DarkCyan)
                    {
                        item.BackgroundImage = new Bitmap(Environment.CurrentDirectory + "\\OpacityFill.png");
                    }
            }
            else if (temp.Name.Contains("picture"))
            {
                PictureBox tempPb = sender as PictureBox;
                foreach (Panel item in panel1.Controls)
                    if (item.Name == tempPb.Parent.Name)
                    {
                        item.BackgroundImage = new Bitmap(Environment.CurrentDirectory + "\\OpacityFill.png");
                    }
            }
            else if (temp.Name.Contains("label"))
            {
                Label tempLb = sender as Label;
                foreach (Panel item in panel1.Controls)
                    if (item.Name == tempLb.Parent.Name)
                    {
                        item.BackgroundImage = new Bitmap(Environment.CurrentDirectory + "\\OpacityFill.png");
                    }
            }
        }

        private void panelFeatureMouseLeave(object sender, EventArgs e)
        {
            foreach (Panel item in panel1.Controls)
            {
                item.BackgroundImage = null;
            }
        }

        private void panelFeatureClicked(object sender, EventArgs e)
        {
            var tempControl = sender as Control;
            string menuName = "";
            if (tempControl.Name.Contains("pnl"))
                menuName = tempControl.Name;
            else
                menuName = tempControl.Parent.Name;
            foreach (Panel item in panel1.Controls)
                if (item.Name == menuName)
                {
                    item.BackColor = Color.DarkCyan;
                }
                else
                    item.BackColor = Color.Transparent;

            foreach (var item in this.Controls)
                if (item.GetType() == typeof(MdiClient))
                {
                    MdiClient client = item as MdiClient;
                    client.Controls.Clear();
                }

            if (objNhanVien._level == 3)
                switch (menuName)
                {
                    case "pnlHangHoa":
                        frmQLHangHoa frmHH = new frmQLHangHoa();
                        frmHH.MdiParent = this;
                        frmHH.Show();
                        break;
                    case "pnlHoaDon":
                        frmQLHoaDon frmHD = new frmQLHoaDon(objNhanVien);
                        frmHD.MdiParent = this;
                        frmHD.Show();
                        break;
                    case "pnlKhachHang":
                        frmQLKhachHang frmKH = new frmQLKhachHang();
                        frmKH.MdiParent = this;
                        frmKH.Show();
                        break;
                    case "pnlKhuyenMai":
                        frmQLKhuyenMai frmKM = new frmQLKhuyenMai();
                        frmKM.MdiParent = this;
                        frmKM.Show();
                        break;
                    case "pnlNhanVien":
                        frmQLNhanVien frmNV = new frmQLNhanVien();
                        frmNV.MdiParent = this;
                        frmNV.Show();
                        break;
                    case "pnlNPP":
                        frmQLNPP frmNPP = new frmQLNPP();
                        frmNPP.MdiParent = this;
                        frmNPP.Show();
                        break;
                }
            else
                switch (menuName)
                {
                    case "pnlHoaDon":
                        frmQLHoaDon frmQLHD = new frmQLHoaDon(objNhanVien);
                        frmQLHD.MdiParent = this;
                        frmQLHD.Show();
                        break;

                    default:
                        MessageBox.Show("Rất tiếc, tài khoản của bạn không có quyền thực hiện chức năng này !");
                        break;
                }
        }



        private void AccountClick(object sender, EventArgs e)
        {
            cmnuAccountMenu.Show(btnAvatar, new Point(0, btnAvatar.Height));
        }

        private void mnuQuit_Click(object sender, EventArgs e)
        {
            isQuit = true;
            this.Close();
        }

        private void mnuLogOut_Click(object sender, EventArgs e)
        {
            isQuit = false;
            this.Close();
        }

        private void pnlHangHoa_Paint(object sender, PaintEventArgs e)
        {

        }


    }
}
